
package Presentacion.contabilidad;

import clases.incio.ButtonRenderer;
import clases.incio.ButtonEditor;
import javax.swing.JCheckBox;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;


public final class dlgAsientoPredifinido extends javax.swing.JDialog {
  
    public static frmConsultaAsiento asiento;
    public static dlgConsultaCuenta consulta;
    private DefaultTableModel modelo;
    private String[] fila;
    private float sumdebe, sumhaber;

    public dlgAsientoPredifinido(frmConsultaAsiento parent, boolean modal) {
        asiento=parent;
        this.setModal(modal);
        initComponents();
        this.setLocationRelativeTo(this);
        this.iniciar();
        this.visiblidad(true);
        sumdebe=0; sumhaber=0;
    }
    
    public void llenardatosAsiento(){
    this.txtnumero.setText(Integer.toString(asiento.objAsiento.getNumero()));
    this.txtdocumento.setText(asiento.objAsiento.getDocumento());
    this.cbotipo.setSelectedItem(asiento.objAsiento.getTipo());
    this.txtdescripcion.setText(asiento.objAsiento.getDescripcion());
    this.dtfecha.setDate(global.Util.StringaDate(asiento.objAsiento.getFecha()));
    this.armarmodelo();
    asiento.objAsiento.llenardatosDetalleAsiento(modelo, tblasiento);
    }
    
    private void mostrarConsulta(){
    //consulta= new dlgConsultaCuenta(this, true);
    consulta.setVisible(true);
    
    }
    
    public void limpiar(){
    this.txtcuenta.setText("");
    this.txtcodigo.setText("");
    this.txtdebe.setText("00.00");
    this.txthaber.setText("00.00");
    
    }
    private void armarmodelo(){
    
    modelo = new DefaultTableModel() {
       @Override
       public boolean isCellEditable(int fila, int columna) {
           return columna==2 || columna ==3 || columna==4; 
       }
    };
    this.tblasiento.removeAll();
    tblasiento.setModel(modelo);
    modelo.addColumn("Codigo");
    modelo.addColumn("Cuenta");
    modelo.addColumn("Debe");
    modelo.addColumn("Haber");
    modelo.addColumn("Quitar");
    DefaultTableCellRenderer centrar=new DefaultTableCellRenderer();
    centrar.setHorizontalAlignment(SwingConstants.RIGHT);
    this.tblasiento.getColumnModel().getColumn(2).setCellRenderer(centrar);
    this.tblasiento.getColumnModel().getColumn(3).setCellRenderer(centrar);
   
     TableColumn  columna= new TableColumn();
     
      columna=this.tblasiento.getColumnModel().getColumn(1);
      columna.setPreferredWidth(300);
      columna=this.tblasiento.getColumnModel().getColumn(4);
      columna.setPreferredWidth(10);
    }
    
    private void agregar(){
       
    if(!global.Validaciones.comprobarNulo(txtcuenta)){
        global.Mensajes.mostrarMensaje("Asiento", "Debe selecionar la cuenta", 2);
    
    }else if (this.verificarCuenta()==true){
        global.Mensajes.mostrarMensaje("Asiento", "La cuenta ya esta ingresada", 3);
    
    }else{
    fila=new String[5];
    fila[0]=this.txtcodigo.getText();
    fila[1]=this.txtcuenta.getText();
    fila[2]=this.txtdebe.getText();
    fila[3]=this.txthaber.getText();
    this.tblasiento.getColumnModel().getColumn(4).setCellRenderer(new ButtonRenderer());
    this.tblasiento.getColumnModel().getColumn(4).setCellEditor(
    new ButtonEditor(new JCheckBox(), modelo, tblasiento));
    
    modelo.addRow(fila);
    }
    }
    
    private void iniciar(){
    this.txtdebe.setHorizontalAlignment(SwingConstants.RIGHT);
    this.txthaber.setHorizontalAlignment(SwingConstants.RIGHT);
    this.txtnumero.setText(Integer.toString(dlgAsientoPredifinido.asiento.objAsiento.numero()));
    this.txtnumero.setEditable(false);
    this.dtfecha.setDate(global.Util.StringaDate(global.Util.getFechaActual()));
    this.cbotipo.setSelectedIndex(0);
    this.txtdocumento.setText("");
    this.txtdescripcion.setText("");
    this.txtcodigo.setEditable(false);
    this.txtcuenta.setEditable(false);
    this.cbotipo.requestFocus();
    this.limpiar();
    this.armarmodelo();
    
    }
    
     private boolean verificarCuenta(){
       for (int i=0; i < this.modelo.getRowCount(); i++){
        if(this.tblasiento.getValueAt(i, 0).equals(this.txtcodigo.getText())){
          return true ;
            }
      
        }return false;
    }
     
    public void visiblidad(boolean visibilidad){
        if(visibilidad!=true){
            this.btnactualizar.setVisible(true);
            this.btnguardar.setVisible(false);
        }else{
            this.btnactualizar.setVisible(false);
            this.btnguardar.setVisible(true);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar4 = new javax.swing.JToolBar();
        btnnuevo = new javax.swing.JButton();
        btnguardar = new javax.swing.JButton();
        btnactualizar = new javax.swing.JButton();
        btnsalir = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        txtnumero = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        dtfecha = new com.toedter.calendar.JDateChooser();
        jLabel2 = new javax.swing.JLabel();
        cbotipo = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        txtdocumento = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        txtdescripcion = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblasiento = new javax.swing.JTable();
        jLabel11 = new javax.swing.JLabel();
        txtcodigo = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        txtcuenta = new javax.swing.JTextField();
        txtdebe = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        txthaber = new javax.swing.JTextField();
        btnagregar = new javax.swing.JButton();
        btnbuscar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jToolBar4.setBorder(null);
        jToolBar4.setFloatable(false);
        jToolBar4.setBorderPainted(false);

        btnnuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/acciones/nuevo.png"))); // NOI18N
        btnnuevo.setFocusable(false);
        btnnuevo.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnnuevo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnnuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnnuevoActionPerformed(evt);
            }
        });
        jToolBar4.add(btnnuevo);

        btnguardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/acciones/guardar.png"))); // NOI18N
        btnguardar.setFocusable(false);
        btnguardar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnguardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnguardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnguardarActionPerformed(evt);
            }
        });
        jToolBar4.add(btnguardar);

        btnactualizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/menu/ImgPrint.png"))); // NOI18N
        btnactualizar.setFocusable(false);
        btnactualizar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnactualizar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnactualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnactualizarActionPerformed(evt);
            }
        });
        jToolBar4.add(btnactualizar);

        btnsalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/menu/ImgCancel.png"))); // NOI18N
        btnsalir.setFocusable(false);
        btnsalir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnsalir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnsalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnsalirActionPerformed(evt);
            }
        });
        jToolBar4.add(btnsalir);

        txtnumero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtnumeroActionPerformed(evt);
            }
        });

        jLabel1.setText("Número");

        jLabel3.setText("Fecha");

        jLabel2.setText("Tipo de Asiento");

        cbotipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--Seleccione--", "Apertura", "Manual", "Ajuste", "Importado", "Cierre" }));

        jLabel4.setText("Documento");

        txtdocumento.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtdocumentoKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtdocumentoKeyTyped(evt);
            }
        });

        jLabel13.setText("Descripcion");

        txtdescripcion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtdescripcionKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtdescripcionKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel13)
                    .addComponent(jLabel1)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtnumero, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(dtfecha, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(cbotipo, 0, 100, Short.MAX_VALUE)
                            .addComponent(txtdocumento))
                        .addGap(110, 110, 110))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(txtdescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(txtnumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbotipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(dtfecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4)
                        .addComponent(txtdocumento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(txtdescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tblasiento.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "null"
            }
        ));
        tblasiento.setColumnSelectionAllowed(true);
        jScrollPane2.setViewportView(tblasiento);
        tblasiento.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel11.setText("Codigo");

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel12.setText("Cuenta");

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel14.setText("Debe");

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel15.setText("Haber");

        btnagregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/acciones/agregar.png"))); // NOI18N
        btnagregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnagregarActionPerformed(evt);
            }
        });

        btnbuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/acciones/buscar.png"))); // NOI18N
        btnbuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnbuscarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jScrollPane2)
                        .addContainerGap())
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(txtcodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnbuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel12)
                            .addComponent(txtcuenta, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtdebe, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel14))
                        .addGap(37, 37, 37)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel15)
                                .addGap(67, 67, 67))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(txthaber, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btnagregar, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap())))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel14)
                            .addComponent(jLabel15))
                        .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(txtcodigo)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txthaber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtdebe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtcuenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(btnbuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                    .addComponent(btnagregar))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jToolBar4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jToolBar4, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnnuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnnuevoActionPerformed
       this.iniciar();
        this.visiblidad(true);
    }//GEN-LAST:event_btnnuevoActionPerformed

    private void btnguardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnguardarActionPerformed
        this.sumdebe=0; this.sumhaber=0;
            for (int i=0; i < this.modelo.getRowCount(); i++){
              this.sumdebe=this.sumdebe+ Float.parseFloat(this.tblasiento.getValueAt(i, 2).toString());
              this.sumhaber=this.sumhaber+ Float.parseFloat(this.tblasiento.getValueAt(i, 3).toString());
            }
        if(this.cbotipo.getSelectedIndex()==0){
       global.Mensajes.mostrarMensaje("Asiento", "Debe seleccionar el tipo", 2);
       }else if(this.tblasiento.getRowCount()==0){
       global.Mensajes.mostrarMensaje("Asiento", "No ha ingresado cuenta(s) en el Asiento", 2);
       
       }else if(this.tblasiento.getRowCount()==1){
       global.Mensajes.mostrarMensaje("Asiento", "Un asiento tiene mas de una cuenta...", 2);
       }else if(this.sumdebe!=this.sumhaber){
           global.Mensajes.mostrarMensaje("Asiento", "El asiento no esta cuadrado...!", 2);
       }else{
       asiento.objAsiento.setDocumento(this.txtdocumento.getText());
       asiento.objAsiento.setFecha(global.Util.DateaString(this.dtfecha.getDate()));
       asiento.objAsiento.setTipo(this.cbotipo.getSelectedItem().toString());
       asiento.objAsiento.setDescripcion(this.txtdescripcion.getText());
       asiento.objAsiento.guardarAsiento();
       for (int i=0; i < this.modelo.getRowCount(); i++){
        asiento.objAsiento.setCodigocuenta(this.tblasiento.getValueAt(i, 0).toString());
        asiento.objAsiento.setDebe(Float.parseFloat(this.tblasiento.getValueAt(i, 2).toString()));
        asiento.objAsiento.setHaber(Float.parseFloat(this.tblasiento.getValueAt(i, 3).toString()));
        asiento.objAsiento.GuardarDetalleAsiento();
          
            }
       global.Mensajes.mostrarMensaje("Asiento", "Datos guardados correctamente...", 1);
       this.iniciar();
       asiento.generartabla();
      
       }
    }//GEN-LAST:event_btnguardarActionPerformed

    private void btnactualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnactualizarActionPerformed
       this.sumdebe=0; this.sumhaber=0;
            for (int i=0; i < this.modelo.getRowCount(); i++){
              this.sumdebe=this.sumdebe+ Float.parseFloat(this.tblasiento.getValueAt(i, 2).toString());
              this.sumhaber=this.sumhaber+ Float.parseFloat(this.tblasiento.getValueAt(i, 3).toString());
           
            }
       if(this.cbotipo.getSelectedIndex()==0){
       global.Mensajes.mostrarMensaje("Asiento", "Debe seleccionar el tipo", 2);
       }else if(this.tblasiento.getRowCount()==0){
       global.Mensajes.mostrarMensaje("Asiento", "No ha ingresado cuenta(s) en el Asiento", 2);
       
       }else if(this.tblasiento.getRowCount()==1){
       global.Mensajes.mostrarMensaje("Asiento", "Un asiento tiene mas de una cuenta...", 2);
       }else if(this.sumdebe!=this.sumhaber){
           global.Mensajes.mostrarMensaje("Asiento", "El asiento no esta cuadrado...!", 2);
       }else{
       asiento.objAsiento.setDocumento(this.txtdocumento.getText());
       asiento.objAsiento.setFecha(global.Util.DateaString(this.dtfecha.getDate()));
       asiento.objAsiento.setTipo(this.cbotipo.getSelectedItem().toString());
       asiento.objAsiento.setDescripcion(this.txtdescripcion.getText());
       asiento.objAsiento.actualizarAsiento();
       asiento.objAsiento.EliminarDetaleAsiento();
       for (int i=0; i < this.modelo.getRowCount(); i++){
        asiento.objAsiento.setCodigocuenta(this.tblasiento.getValueAt(i, 0).toString());
        asiento.objAsiento.setDebe(Float.parseFloat(this.tblasiento.getValueAt(i, 2).toString()));
        asiento.objAsiento.setHaber(Float.parseFloat(this.tblasiento.getValueAt(i, 3).toString()));
        asiento.objAsiento.GuardarDetalleAsiento();
          
            }
       global.Mensajes.mostrarMensaje("Asiento", "Datos actualizados correctamente...", 1);
       this.iniciar();
       asiento.generartabla();
       dispose();
      
       }
    }//GEN-LAST:event_btnactualizarActionPerformed

    private void btnsalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnsalirActionPerformed
        dispose();
        limpiar();
    }//GEN-LAST:event_btnsalirActionPerformed

    private void txtnumeroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtnumeroActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtnumeroActionPerformed

    private void txtdocumentoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtdocumentoKeyReleased
        global.Validaciones.convertirMayuscula(txtdocumento);
    }//GEN-LAST:event_txtdocumentoKeyReleased

    private void txtdocumentoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtdocumentoKeyTyped
        global.Validaciones.numerosLetras(evt, txtdocumento);
    }//GEN-LAST:event_txtdocumentoKeyTyped

    private void txtdescripcionKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtdescripcionKeyReleased
        global.Validaciones.convertirMayuscula(txtdescripcion);
    }//GEN-LAST:event_txtdescripcionKeyReleased

    private void txtdescripcionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtdescripcionKeyTyped
        global.Validaciones.numerosLetras(evt, txtdescripcion);
    }//GEN-LAST:event_txtdescripcionKeyTyped

    private void btnagregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnagregarActionPerformed
        this.agregar();
        this.limpiar();
    }//GEN-LAST:event_btnagregarActionPerformed

    private void btnbuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnbuscarActionPerformed
        this.mostrarConsulta();
        this.txtcuenta.setText(consulta.descripcion);
        this.txtcodigo.setText(consulta.id);
    }//GEN-LAST:event_btnbuscarActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
       this.iniciar();
    }//GEN-LAST:event_formWindowClosed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(dlgAsientoPredifinido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(dlgAsientoPredifinido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(dlgAsientoPredifinido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(dlgAsientoPredifinido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                dlgAsientoPredifinido dialog = new dlgAsientoPredifinido(new frmConsultaAsiento(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnactualizar;
    private javax.swing.JButton btnagregar;
    private javax.swing.JButton btnbuscar;
    private javax.swing.JButton btnguardar;
    private javax.swing.JButton btnnuevo;
    private javax.swing.JButton btnsalir;
    private javax.swing.JComboBox cbotipo;
    private com.toedter.calendar.JDateChooser dtfecha;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JToolBar jToolBar4;
    private javax.swing.JTable tblasiento;
    private javax.swing.JTextField txtcodigo;
    private javax.swing.JTextField txtcuenta;
    private javax.swing.JTextField txtdebe;
    private javax.swing.JTextField txtdescripcion;
    private javax.swing.JTextField txtdocumento;
    private javax.swing.JTextField txthaber;
    private javax.swing.JTextField txtnumero;
    // End of variables declaration//GEN-END:variables
}
